home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / grep.zip / GREP.H < prev    next >
Text File  |  1993-01-04  |  4KB  |  113 lines

  1. #define MAXFILES 600
  2. #define FNASIZE  38912
  3.  
  4. int  getfnl(char *, char *, unsigned, int);
  5. int  strbpl(char **, int, char *);
  6. void file(char *);
  7. void cant(char *);
  8. void toomany(char *);
  9. void help(char **);
  10. void usage(char *);
  11. void compile(char *);
  12. char *cclass(char *, char *);
  13. void store(char);
  14. void badpat(char *, char *, char *);
  15. void grep(FILE *, char *);
  16. int  match(void);
  17. char *pmatch(char *, char *);
  18. void error(char *);
  19.  
  20. char    *documentation[] = {
  21. "grep searches a file for a given pattern.  Execute by",
  22. "   grep [flags] regular_expression file_list",
  23. "",
  24. "Flags are single characters preceeded by '-':",
  25. "   -c      Only a count of matching lines is printed",
  26. "   -f      Print file name for matching lines switch, see below",
  27. "   -n      Each line is preceeded by its line number",
  28. "   -v      Only print non-matching lines",
  29. "",
  30. "The file_list is a list of files (wildcards are acceptable on RSX modes).",
  31.  
  32. "",
  33. "The file name is normally printed if there is a file given.",
  34. "The -f flag reverses this action (print name no file, not if more).",
  35. "",
  36. 0 };
  37.  
  38.  
  39. char    *patdoc[] = {
  40. "The regular_expression defines the pattern to search for.  Upper- and",
  41. "lower-case are always ignored.  Blank lines never match.  The expression",
  42. "should be quoted to prevent file-name translation.",
  43. "x      An ordinary character (not mentioned below) matches that character.",
  44. "'\\'    The backslash quotes any character.  \"\\$\" matches a dollar-sign.",
  45. "'^'    A circumflex at the beginning of an expression matches the",
  46. "       beginning of a line.",
  47. "'$'    A dollar-sign at the end of an expression matches the end of a line.",
  48. "'.'    A period matches any character except \"new-line\".",
  49. "':a'   A colon matches a class of characters described by the following",
  50. "':d'     character.  \":a\" matches any alphabetic, \":d\" matches digits,",
  51. "':n'     \":n\" matches alphanumerics, \": \" matches spaces, tabs, and",
  52. "': '     other control characters, such as new-line.",
  53. "'*'    An expression followed by an asterisk matches zero or more",
  54. "       occurrances of that expression: \"fo*\" matches \"f\", \"fo\"",
  55. "       \"foo\", etc.",
  56. "'+'    An expression followed by a plus sign matches one or more",
  57. "       occurrances of that expression: \"fo+\" matches \"fo\", etc.",
  58. "'-'    An expression followed by a minus sign optionally matches",
  59. "       the expression.",
  60. "'[]'   A string enclosed in square brackets matches any character in",
  61. "       that string, but no others.  If the first character in the",
  62. "       string is a circumflex, the expression matches any character",
  63. "       except \"new-line\" and the characters in the string.  For",
  64. "       example, \"[xyz]\" matches \"xx\" and \"zyx\", while \"[^xyz]\"",
  65. "       matches \"abc\" but not \"axb\".  A range of characters may be",
  66. "       specified by two characters separated by \"-\".  Note that,",
  67. "       [a-z] matches alphabetics, while [z-a] never matches.",
  68. "The concatenation of regular expressions is a regular expression.",
  69. 0};
  70.  
  71. #ifndef stdin
  72. #define stdin STDIN
  73. #define stdout STDOUT
  74. #define stderr STDERR
  75. #define DeSmet 1
  76. #endif
  77.  
  78. #define LMAX    512
  79. #define PMAX    256
  80.  
  81. #define CHAR    1
  82. #define BOL     2
  83. #define EOL     3
  84. #define ANY     4
  85. #define CLASS   5
  86. #define NCLASS  6
  87. #define STAR    7
  88. #define PLUS    8
  89. #define MINUS   9
  90. #define ALPHA   10
  91. #define DIGIT   11
  92. #define NALPHA  12
  93. #define PUNCT   13
  94. #define RANGE   14
  95. #define ENDPAT  15
  96.  
  97. int     cflag;
  98. int     fflag;
  99. int     nflag;
  100. int     vflag;
  101. int     nfile;
  102.  
  103. int     debug   =       0;         /* Set for debug code      */
  104.  
  105. char    *pp;
  106.  
  107. char    lbuf[LMAX];
  108. char    pbuf[PMAX];
  109. char    fnames[FNASIZE], *fpointers[MAXFILES];
  110. int     lfeed = 0;
  111.  
  112. /*******************************************************/
  113.